// [['辣','不辣','中辣','重辣'],['大份','小份', '中份'],['红烧鱼','锅锅芋头','剁椒鱼头','红烧牛腩']]
// [['辣','大份','红烧鱼'],['辣','大份','锅锅芋头'],['辣','大份','剁椒鱼头']]

function compose(arr) {
    if (arr.length === 1) {
      return arr[0].map(x => [x]);
    }
  
    const first = arr[0];
    const rest = arr.slice(1);
    const subResult = compose(rest);
  
    return first.flatMap(x => {
      return subResult.map(y => [x, ...y]);
    });
  }
const data = [['辣','不辣','中辣','重辣'],['大份','小份', '中份'],['红烧鱼','锅锅芋头','剁椒鱼头','红烧牛腩'],[1,2]];

// const result = data.reduce((acc, curr) => {
//     return acc.flatMap(item => {
//       return curr.map(val => {
//         return [...item, val];
//       });
//     });
//   });
  
  const result = compose(data);
console.log(result);